package com.wuzuqing.android.eightdiagrams.hook.testHookers;

import android.content.Context;
import android.os.Build;

import com.swift.sandhook.SandHook;
import com.swift.sandhook.SandHookConfig;
import com.swift.sandhook.wrapper.HookErrorException;

public class HookInit {


    public static void onCreate(Context context) {

        SandHookConfig.DEBUG = false;

        if (Build.VERSION.SDK_INT == 29 && getPreviewSDKInt() > 0) {
            // Android R preview
            SandHookConfig.SDK_INT = 30;
        }
//
        SandHook.disableVMInline();
        SandHook.tryDisableProfile(context.getPackageName());
        SandHook.disableDex2oatInline(false);



        try {
            SandHook.addHookClass(ActivityHooker.class, IPHooker.class, WifiManagerHooker.class);
        } catch (HookErrorException e) {
            e.printStackTrace();
        }
    }

    public static int getPreviewSDKInt() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            try {
                return Build.VERSION.PREVIEW_SDK_INT;
            } catch (Throwable e) {
                // ignore
            }
        }
        return 0;
    }
}
